home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / utilit~1 / gdb35src.zoo / dist-gdb / infrun.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-12  |  44.9 KB  |  1,464 lines

  1. /* Start and stop the inferior process, for GDB.
  2.    Copyright (C) 1986, 1987, 1988, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. GDB is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GDB is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GDB; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* Notes on the algorithm used in wait_for_inferior to determine if we
  21.    just did a subroutine call when stepping.  We have the following
  22.    information at that point:
  23.  
  24.                   Current and previous (just before this step) pc.
  25.           Current and previous sp.
  26.           Current and previous start of current function.
  27.  
  28.    If the start's of the functions don't match, then
  29.  
  30.        a) We did a subroutine call.
  31.  
  32.    In this case, the pc will be at the beginning of a function.
  33.  
  34.     b) We did a subroutine return.
  35.  
  36.    Otherwise.
  37.  
  38.     c) We did a longjmp.
  39.  
  40.    If we did a longjump, we were doing "nexti", since a next would
  41.    have attempted to skip over the assembly language routine in which
  42.    the longjmp is coded and would have simply been the equivalent of a
  43.    continue.  I consider this ok behaivior.  We'd like one of two
  44.    things to happen if we are doing a nexti through the longjmp()
  45.    routine: 1) It behaves as a stepi, or 2) It acts like a continue as
  46.    above.  Given that this is a special case, and that anybody who
  47.    thinks that the concept of sub calls is meaningful in the context
  48.    of a longjmp, I'll take either one.  Let's see what happens.  
  49.  
  50.    Acts like a subroutine return.  I can handle that with no problem
  51.    at all.
  52.  
  53.    -->So: If the current and previous beginnings of the current
  54.    function don't match, *and* the pc is at the start of a function,
  55.    we've done a subroutine call.  If the pc is not at the start of a
  56.    function, we *didn't* do a subroutine call.  
  57.  
  58.    -->If the beginnings of the current and previous function do match,
  59.    either: 
  60.  
  61.        a) We just did a recursive call.
  62.  
  63.        In this case, we would be at the very beginning of a
  64.        function and 1) it will have a prologue (don't jump to
  65.        before prologue, or 2) (we assume here that it doesn't have
  66.        a prologue) there will have been a change in the stack
  67.        pointer over the last instruction.  (Ie. it's got to put
  68.        the saved pc somewhere.  The stack is the usual place.  In
  69.        a recursive call a register is only an option if there's a
  70.        prologue to do something with it.  This is even true on
  71.        register window machines; the prologue sets up the new
  72.        window.  It might not be true on a register window machine
  73.        where the call instruction moved the register window
  74.        itself.  Hmmm.  One would hope that the stack pointer would
  75.        also change.  If it doesn't, somebody send me a note, and
  76.        I'll work out a more general theory.
  77.        randy@wheaties.ai.mit.edu).  This is true (albeit slipperly
  78.        so) on all machines I'm aware of:
  79.  
  80.           m68k:    Call changes stack pointer.  Regular jumps don't.
  81.  
  82.           sparc:    Recursive calls must have frames and therefor,
  83.                     prologues.
  84.  
  85.           vax:    All calls have frames and hence change the
  86.                     stack pointer.
  87.  
  88.     b) We did a return from a recursive call.  I don't see that we
  89.        have either the ability or the need to distinguish this
  90.        from an ordinary jump.  The stack frame will be printed
  91.        when and if the frame pointer changes; if we are in a
  92.        function without a frame pointer, it's the users own
  93.        lookout.
  94.  
  95.     c) We did a jump within a function.  We assume that this is
  96.        true if we didn't do a recursive call.
  97.  
  98.     d) We are in no-man's land ("I see no symbols here").  We
  99.        don't worry about this; it will make calls look like simple
  100.        jumps (and the stack frames will be printed when the frame
  101.        pointer moves), which is a reasonably non-violent response.
  102.  
  103. #if 0
  104.     We skip this; it causes more problems than it's worth.
  105. #ifdef SUN4_COMPILER_FEATURE
  106.     We do a special ifdef for the sun 4, forcing it to single step
  107.   into calls which don't have prologues.  This means that we can't
  108.   nexti over leaf nodes, we can probably next over them (since they
  109.   won't have debugging symbols, usually), and we can next out of
  110.   functions returning structures (with a "call .stret4" at the end).
  111. #endif
  112. #endif
  113. */
  114.    
  115.  
  116.    
  117.    
  118.  
  119. #include <stdio.h>
  120. #include "defs.h"
  121. #include "param.h"
  122. #include "symtab.h"
  123. #include "frame.h"
  124. #include "inferior.h"
  125. #include "wait.h"
  126.  
  127. #include <signal.h>
  128.  
  129. /* unistd.h is needed to #define X_OK */
  130. #ifdef USG
  131. #include <unistd.h>
  132. #else
  133. #include <sys/file.h>
  134. #endif
  135.  
  136. #ifdef UMAX_PTRACE
  137. #include <aouthdr.h>
  138. #include <sys/param.h>
  139. #include <sys/ptrace.h>
  140. #endif /* UMAX_PTRACE */
  141.  
  142. /* Required by <sys/user.h>.  */
  143. #include <sys/types.h>
  144. /* Required by <sys/user.h>, at least on system V.  */
  145. #include <sys/dir.h>
  146. /* Needed by IN_SIGTRAMP on some machines (e.g. vax).  */
  147. #include <sys/param.h>
  148.  
  149. #ifndef atarist
  150. /* Needed by IN_SIGTRAMP on some machines (e.g. vax).  */
  151. #include <sys/user.h>
  152. #endif
  153.  
  154. extern char *sys_siglist[];
  155. extern int errno;
  156.  
  157. /* Sigtramp is a routine that the kernel calls (which then calls the
  158.    signal handler).  On most machines it is a library routine that
  159.    is linked into the executable.
  160.  
  161.    This macro, given a program counter value and the name of the
  162.    function in which that PC resides (which can be null if the
  163.    name is not known), returns nonzero if the PC and name show
  164.    that we are in sigtramp.
  165.  
  166.    On most machines just see if the name is sigtramp (and if we have
  167.    no name, assume we are not in sigtramp).  */
  168. #if !defined (IN_SIGTRAMP)
  169. #define IN_SIGTRAMP(pc, name) \
  170.   name && !strcmp ("_sigtramp", name)
  171. #endif
  172.  
  173. /* Tables of how to react to signals; the user sets them.  */
  174.  
  175. static char signal_stop[NSIG];
  176. static char signal_print[NSIG];
  177. static char signal_program[NSIG];
  178.  
  179. /* Nonzero if breakpoints are now inserted in the inferior.  */
  180.  
  181. static int breakpoints_inserted;
  182.  
  183. /* Function inferior was in as of last step command.  */
  184.  
  185. static struct symbol *step_start_function;
  186.  
  187. /* This is the sequence of bytes we insert for a breakpoint.  */
  188.  
  189. static char break_insn[] = BREAKPOINT;
  190.  
  191. /* Nonzero => address for special breakpoint for resuming stepping.  */
  192.  
  193. static CORE_ADDR step_resume_break_address;
  194.  
  195. /* Original contents of the byte where the special breakpoint is.  */
  196.  
  197. static char step_resume_break_shadow[sizeof break_insn];
  198.  
  199. /* Nonzero means the special breakpoint is a duplicate
  200.    so it has not itself been inserted.  */
  201.  
  202. static int step_resume_break_duplicate;
  203.  
  204. /* Nonzero if we are expecting a trace trap and should proceed from it.
  205.    2 means expecting 2 trace traps and should continue both times.
  206.    That occurs when we tell sh to exec the program: we will get
  207.    a trap after the exec of sh and a second when the program is exec'd.  */
  208.  
  209. static int trap_expected;
  210.  
  211. /* Nonzero if the next time we try to continue the inferior, it will
  212.    step one instruction and generate a spurious trace trap.
  213.    This is used to compensate for a bug in HP-UX.  */
  214.  
  215. static int trap_expected_after_continue;
  216.  
  217. /* Nonzero means expecting a trace trap
  218.    and should stop the inferior and return silently when it happens.  */
  219.  
  220. int stop_after_trap;
  221.  
  222. /* Nonzero means expecting a trace trap due to attaching to a process.  */
  223.  
  224. int stop_after_attach;
  225.  
  226. /* Nonzero if pc has been changed by the debugger
  227.    since the inferior stopped.  */
  228.  
  229. int pc_changed;
  230.  
  231. /* Nonzero if debugging a remote machine via a serial link or ethernet.  */
  232.  
  233. int remote_debugging;
  234.  
  235. /* Save register contents here when about to pop a stack dummy frame.  */
  236.  
  237. char stop_registers[REGISTER_BYTES];
  238.  
  239. /* Nonzero if program stopped due to error trying to insert breakpoints.  */
  240.  
  241. static int breakpoints_failed;
  242.  
  243. /* Nonzero if inferior is in sh before our program got exec'd.  */
  244.  
  245. static int running_in_shell;
  246.  
  247. /* Nonzero after stop if current stack frame should be printed.  */
  248.  
  249. static int stop_print_frame;
  250.  
  251. #ifdef NO_SINGLE_STEP
  252. extern int one_stepped;        /* From machine dependent code */
  253. extern void single_step ();    /* Same. */
  254. #endif /* NO_SINGLE_STEP */
  255.  
  256. static void insert_step_breakpoint ();
  257. static void remove_step_breakpoint ();
  258. static void wait_for_inferior ();
  259. static void normal_stop ();
  260.  
  261.  
  262. /* Clear out all variables saying what to do when inferior is continued.
  263.    First do this, then set the ones you want, then call `proceed'.  */
  264.  
  265. void
  266. clear_proceed_status ()
  267. {
  268.   trap_expected = 0;
  269.   step_range_start = 0;
  270.   step_range_end = 0;
  271.   step_frame_address = 0;
  272.   step_over_calls = -1;
  273.   step_resume_break_address = 0;
  274.   stop_after_trap = 0;
  275.   stop_after_attach = 0;
  276.  
  277.   /* Discard any remaining commands left by breakpoint we had stopped at.  */
  278.   clear_breakpoint_commands ();
  279. }
  280.  
  281. /* Basic routine for continuing the program in various fashions.
  282.  
  283.    ADDR is the address to resume at, or -1 for resume where stopped.
  284.    SIGNAL is the signal to give it, or 0 for none,
  285.      or -1 for act according to how it stopped.
  286.    STEP is nonzero if should trap after one instruction.
  287.      -1 means return after that and print nothing.
  288.      You should probably set various step_... variables
  289.      before calling here, if you are stepping.
  290.  
  291.    You should call clear_proceed_status before calling proceed.  */
  292.  
  293. void
  294. proceed (addr, signal, step)
  295.      CORE_ADDR addr;
  296.      int signal;
  297.      int step;
  298. {
  299.   int oneproc = 0;
  300.  
  301.   if (step > 0)
  302.     step_start_function = find_pc_function (read_pc ());
  303.   if (step < 0)
  304.     stop_after_trap = 1;
  305.  
  306.   if (addr == -1)
  307.     {
  308.       /* If there is a breakpoint at the address we will resume at,
  309.      step one instruction before inserting breakpoints
  310.      so that we do not stop right away.  */
  311.  
  312.       if (!pc_changed && breakpoint_here_p (read_pc ()))
  313.     oneproc = 1;
  314.     }
  315.   else
  316.     {
  317.       write_register (PC_REGNUM, addr);
  318. #ifdef NPC_REGNUM
  319.       write_register (NPC_REGNUM, addr + 4);
  320. #endif
  321.     }
  322.  
  323.   if (trap_expected_after_continue)
  324.     {
  325.       /* If (step == 0), a trap will be automatically generated after
  326.      the first instruction is executed.  Force step one
  327.      instruction to clear this condition.  This should not occur
  328.      if step is nonzero, but it is harmless in that case.  */
  329.       oneproc = 1;
  330.       trap_expected_after_continue = 0;
  331.     }
  332.  
  333.   if (oneproc)
  334.     /* We will get a trace trap after one instruction.
  335.        Continue it automatically and insert breakpoints then.  */
  336.     trap_expected = 1;
  337.   else
  338.     {
  339.       int temp = insert_breakpoints ();
  340.       if (temp)
  341.     {
  342.       print_sys_errmsg ("ptrace", temp);
  343.       error ("Cannot insert breakpoints.\n\
  344. The same program may be running in another process.");
  345.     }
  346.       breakpoints_inserted = 1;
  347.     }
  348.  
  349.   /* Install inferior's terminal modes.  */
  350.   terminal_inferior ();
  351.  
  352.   if (signal >= 0)
  353.     stop_signal = signal;
  354.   /* If this signal should not be seen by program,
  355.      give it zero.  Used for debugging signals.  */
  356.   else if (stop_signal < NSIG && !signal_program[stop_signal])
  357.     stop_signal= 0;
  358.  
  359.   /* Resume inferior.  */
  360.   resume (oneproc || step, stop_signal);
  361.  
  362.   /* Wait for it to stop (if not standalone)
  363.      and in any case decode why it stopped, and act accordingly.  */
  364.  
  365.   wait_for_inferior ();
  366.   normal_stop ();
  367. }
  368.  
  369. /* Writing the inferior pc as a register calls this function
  370.    to inform infrun that the pc has been set in the debugger.  */
  371.  
  372. void
  373. writing_pc (val)
  374.      CORE_ADDR val;
  375. {
  376.   stop_pc = val;
  377.   pc_changed = 1;
  378. }
  379.  
  380. /* Start an inferior process for the first time.
  381.    Actually it was started by the fork that created it,
  382.    but it will have stopped one instruction after execing sh.
  383.    Here we must get it up to actual execution of the real program.  */
  384.  
  385. void
  386. start_inferior ()
  387. {
  388.   /* We will get a trace trap after one instruction.
  389.      Continue it automatically.  Eventually (after shell does an exec)
  390.      it will get another trace trap.  Then insert breakpoints and continue.  */
  391.  
  392. #ifdef START_INFERIOR_TRAPS_EXPECTED
  393.   trap_expected = START_INFERIOR_TRAPS_EXPECTED;
  394. #else
  395.   trap_expected = 2;
  396. #endif
  397.  
  398.   running_in_shell = 0;        /* Set to 1 at first SIGTRAP, 0 at second.  */
  399.   trap_expected_after_continue = 0;
  400.   breakpoints_inserted = 0;
  401.   mark_breakpoints_out ();
  402.  
  403. #ifdef atarist
  404.     insert_breakpoints();
  405.     breakpoints_inserted=1;
  406. #endif
  407.  
  408.   /* Set up the "saved terminal modes" of the inferior
  409.      based on what modes we are starting it with.  */
  410.   terminal_init_inferior ();
  411.  
  412.   /* Install inferior's terminal modes.  */
  413.   terminal_inferior ();
  414.  
  415.   if (remote_debugging)
  416.     {
  417.       trap_expected = 0;
  418.       fetch_inferior_registers();
  419.       set_current_frame (create_new_frame (read_register (FP_REGNUM),
  420.                        read_pc ()));
  421.       stop_frame_address = FRAME_FP (get_current_frame());
  422.       inferior_pid = 3;
  423.       if (insert_breakpoints())
  424.     fatal("Can't insert breakpoints");
  425.       breakpoints_inserted = 1;
  426.       proceed(-1, -1, 0);
  427.     }
  428.   else
  429.     {
  430.       wait_for_inferior ();
  431.       normal_stop ();
  432.     }
  433. }
  434.  
  435. /* Start remote-debugging of a machine over a serial link.  */
  436.  
  437. void
  438. start_remote ()
  439. {
  440.   clear_proceed_status ();
  441.   running_in_shell = 0;
  442.   trap_expected = 0;
  443.   inferior_pid = 3;
  444.   breakpoints_inserted = 0;
  445.   mark_breakpoints_out ();
  446.   wait_for_inferior ();
  447.   normal_stop();
  448. }
  449.  
  450. #ifdef ATTACH_DETACH
  451.  
  452. /* Attach to process PID, then initialize for debugging it
  453.    and wait for the trace-trap that results from attaching.  */
  454.  
  455. void
  456. attach_program (pid)
  457.      int pid;
  458. {
  459.   attach (pid);
  460.   inferior_pid = pid;
  461.  
  462.   mark_breakpoints_out ();
  463.   terminal_init_inferior ();
  464.   clear_proceed_status ();
  465.   stop_after_attach = 1;
  466.   /*proceed (-1, 0, -2);*/
  467.   terminal_inferior ();
  468.   wait_for_inferior ();
  469.   normal_stop ();
  470. }
  471. #endif /* ATTACH_DETACH */
  472.  
  473. /* Wait for control to return from inferior to debugger.
  474.    If inferior gets a signal, we may decide to start it up again
  475.    instead of returning.  That is why there is a loop in this function.
  476.    When this function actually returns it means the inferior
  477.    should be left stopped and GDB should read more commands.  */
  478.  
  479. static void
  480. wait_for_inferior ()
  481. {
  482.   register int pid;
  483.   WAITTYPE w;
  484.   CORE_ADDR pc;
  485.   int tem;
  486.   int another_trap;
  487.   int random_signal;
  488.   CORE_ADDR stop_sp, prev_sp;
  489.   CORE_ADDR prev_func_start, stop_func_start;
  490.   char *prev_func_name, *stop_func_name;
  491.   CORE_ADDR prologue_pc;
  492.   int stop_step_resume_break;
  493.   CORE_ADDR step_resume_break_sp;
  494.   int newmisc;
  495.   int newfun_pc;
  496.   struct symtab_and_line sal;
  497.   int prev_pc;
  498.   extern CORE_ADDR text_end;
  499.   int remove_breakpoints_on_following_step = 0;
  500.  
  501.   prev_pc = read_pc ();
  502.   (void) find_pc_partial_function (prev_pc, &prev_func_name,
  503.                    &prev_func_start);
  504.   prev_func_start += FUNCTION_START_OFFSET;
  505.   prev_sp = read_register (SP_REGNUM);
  506.  
  507.   while (1)
  508.     {
  509.       /* Clean up saved state that will become invalid.  */
  510.       pc_changed = 0;
  511.       flush_cached_frames ();
  512.  
  513.       if (remote_debugging)
  514.     remote_wait (&w);
  515.       else
  516.     {
  517.       pid = wait (&w);
  518.       if (pid != inferior_pid)
  519.         continue;
  520.     }
  521.  
  522.       /* See if the process still exists; clean up if it doesn't.  */
  523.       if (WIFEXITED (w))
  524.     {
  525.       terminal_ours_for_output ();
  526.       if (WRETCODE (w))
  527.         printf ("\nProgram exited with code 0%o.\n", WRETCODE (w));
  528.       else
  529.         printf ("\nProgram exited normally.\n");
  530.       fflush (stdout);
  531.       inferior_died ();
  532. #ifdef NO_SINGLE_STEP
  533.       one_stepped = 0;
  534. #endif
  535.       stop_print_frame = 0;
  536.       break;
  537.     }
  538.       else if (!WIFSTOPPED (w))
  539.     {
  540.       kill_inferior ();
  541.       stop_print_frame = 0;
  542.       stop_signal = WTERMSIG (w);
  543.       terminal_ours_for_output ();
  544.       printf ("\nProgram terminated with signal %d, %s\n",
  545.           stop_signal,
  546.           stop_signal < NSIG
  547.           ? sys_siglist[stop_signal]
  548.           : "(undocumented)");
  549.       printf ("The inferior process no longer exists.\n");
  550.       fflush (stdout);
  551. #ifdef NO_SINGLE_STEP
  552.       one_stepped = 0;
  553. #endif
  554.       break;
  555.     }
  556.       
  557. #ifdef NO_SINGLE_STEP
  558.       if (one_stepped)
  559.     single_step (0);    /* This actually cleans up the ss */
  560. #endif /* NO_SINGLE_STEP */
  561.       
  562.       fetch_inferior_registers ();
  563.       stop_pc = read_pc ();
  564.       set_current_frame ( create_new_frame (read_register (FP_REGNUM),
  565.                         read_pc ()));
  566.       
  567.       stop_frame_address = FRAME_FP (get_current_frame ());
  568.       stop_sp = read_register (SP_REGNUM);
  569.       stop_func_start = 0;
  570.       stop_func_name = 0;
  571.       /* Don't care about return value; stop_func_start and stop_func_name
  572.      will both be 0 if it doesn't work.  */
  573.       (void) find_pc_partial_function (stop_pc, &stop_func_name,
  574.                        &stop_func_start);
  575.       stop_func_start += FUNCTION_START_OFFSET;
  576.       another_trap = 0;
  577.       stop_breakpoint = 0;
  578.       stop_step = 0;
  579.       stop_stack_dummy = 0;
  580.       stop_print_frame = 1;
  581.       stop_step_resume_break = 0;
  582.       random_signal = 0;
  583.       stopped_by_random_signal = 0;
  584.       breakpoints_failed = 0;
  585.       
  586.       /* Look at the cause of the stop, and decide what to do.
  587.      The alternatives are:
  588.      1) break; to really stop and return to the debugger,
  589.      2) drop through to start up again
  590.      (set another_trap to 1 to single step once)
  591.      3) set random_signal to 1, and the decision between 1 and 2
  592.      will be made according to the signal handling tables.  */
  593.       
  594.       stop_signal = WSTOPSIG (w);
  595.       
  596.       /* First, distinguish signals caused by the debugger from signals
  597.      that have to do with the program's own actions.
  598.      Note that breakpoint insns may cause SIGTRAP or SIGILL
  599.      or SIGEMT, depending on the operating system version.
  600.      Here we detect when a SIGILL or SIGEMT is really a breakpoint
  601.      and change it to SIGTRAP.  */
  602.       
  603.       if (stop_signal == SIGTRAP
  604.       || (breakpoints_inserted &&
  605.           (stop_signal == SIGILL
  606.            || stop_signal == SIGEMT))
  607.       || stop_after_attach)
  608.     {
  609. #ifdef atarist
  610. /* on the ST, a SIGILL *COULD* mean a breakpoint, so if it is,
  611.    set the signal to SIGTRAP, and proceed further... */
  612.  
  613.        char this_insn[sizeof(break_insn)];
  614.  
  615.        read_inferior_memory(stop_pc - DECR_PC_AFTER_BREAK, &this_insn, sizeof(break_insn));
  616.         if(stop_signal == SIGILL &&  *(short *)this_insn == *(short *)break_insn)
  617.             stop_signal = SIGTRAP;
  618. #endif
  619.  
  620.       if (stop_signal == SIGTRAP && stop_after_trap)
  621.         {
  622.           stop_print_frame = 0;
  623.           break;
  624.         }
  625.       if (stop_after_attach)
  626.         break;
  627.       /* Don't even think about breakpoints
  628.          if still running the shell that will exec the program
  629.          or if just proceeded over a breakpoint.  */
  630.       if (stop_signal == SIGTRAP && trap_expected)
  631.         stop_breakpoint = 0;
  632.       else
  633.         {
  634.           /* See if there is a breakpoint at the current PC.  */
  635. #if DECR_PC_AFTER_BREAK
  636.           /* Notice the case of stepping through a jump
  637.          that leads just after a breakpoint.
  638.          Don't confuse that with hitting the breakpoint.
  639.          What we check for is that 1) stepping is going on
  640.          and 2) the pc before the last insn does not match
  641.          the address of the breakpoint before the current pc.  */
  642.           if (!(prev_pc != stop_pc - DECR_PC_AFTER_BREAK
  643.             && step_range_end && !step_resume_break_address))
  644. #endif /* DECR_PC_AFTER_BREAK not zero */
  645.         {
  646.           /* See if we stopped at the special breakpoint for
  647.              stepping over a subroutine call.  */
  648.           if (stop_pc - DECR_PC_AFTER_BREAK
  649.               == step_resume_break_address)
  650.             {
  651.               stop_step_resume_break = 1;
  652.               if (DECR_PC_AFTER_BREAK)
  653.             {
  654.               stop_pc -= DECR_PC_AFTER_BREAK;
  655.               write_register (PC_REGNUM, stop_pc);
  656.               pc_changed = 0;
  657.             }
  658.             }
  659.           else
  660.             {
  661.               stop_breakpoint =
  662.             breakpoint_stop_status (stop_pc, stop_frame_address);
  663.               /* Following in case break condition called a
  664.              function.  */
  665.               stop_print_frame = 1;
  666.               if (stop_breakpoint && DECR_PC_AFTER_BREAK)
  667.             {
  668.               stop_pc -= DECR_PC_AFTER_BREAK;
  669.               write_register (PC_REGNUM, stop_pc);
  670. #ifdef NPC_REGNUM
  671.               write_register (NPC_REGNUM, stop_pc + 4);
  672. #endif
  673.               pc_changed = 0;
  674.             }
  675.             }
  676.         }
  677.         }
  678.       
  679.       if (stop_signal == SIGTRAP)
  680.         random_signal
  681.           = !(stop_breakpoint || trap_expected
  682.           || stop_step_resume_break
  683. #ifndef CANNOT_EXECUTE_STACK
  684.           || (stop_sp INNER_THAN stop_pc
  685.               && stop_pc INNER_THAN stop_frame_address)
  686. #else
  687.           || stop_pc == text_end - 2
  688. #endif
  689.           || (step_range_end && !step_resume_break_address));
  690.       else
  691.         {
  692.           random_signal
  693.         = !(stop_breakpoint
  694.             || stop_step_resume_break
  695. #ifdef sony_news
  696.             || (stop_sp INNER_THAN stop_pc
  697.             && stop_pc INNER_THAN stop_frame_address)
  698. #endif
  699.             
  700.             );
  701.           if (!random_signal)
  702.         stop_signal = SIGTRAP;
  703.         }
  704.     }
  705.       else
  706.     random_signal = 1;
  707.       
  708.       /* For the program's own signals, act according to
  709.      the signal handling tables.  */
  710.       
  711.       if (random_signal
  712.       && !(running_in_shell && stop_signal == SIGSEGV))
  713.     {
  714.       /* Signal not for debugging purposes.  */
  715.       int printed = 0;
  716.       
  717.       stopped_by_random_signal = 1;
  718.       
  719.       if (stop_signal >= NSIG
  720.           || signal_print[stop_signal])
  721.         {
  722.           printed = 1;
  723.           terminal_ours_for_output ();
  724.           printf ("\nProgram received signal %d, %s\n",
  725.               stop_signal,
  726.               stop_signal < NSIG
  727.               ? sys_siglist[stop_signal]
  728.               : "(undocumented)");
  729.           fflush (stdout);
  730.         }
  731.       if (stop_signal >= NSIG
  732.           || signal_stop[stop_signal])
  733.         break;
  734.       /* If not going to stop, give terminal back
  735.          if we took it away.  */
  736.       else if (printed)
  737.         terminal_inferior ();
  738.     }
  739.       
  740.       /* Handle cases caused by hitting a breakpoint.  */
  741.       
  742.       if (!random_signal
  743.       && (stop_breakpoint || stop_step_resume_break))
  744.     {
  745.       /* Does a breakpoint want us to stop?  */
  746.       if (stop_breakpoint && stop_breakpoint != -1
  747.           && stop_breakpoint != -0x1000001)
  748.         {
  749.           /* 0x1000000 is set in stop_breakpoint as returned by
  750.          breakpoint_stop_status to indicate a silent
  751.          breakpoint.  */
  752.           if ((stop_breakpoint > 0 ? stop_breakpoint :
  753.            -stop_breakpoint)
  754.           & 0x1000000)
  755.         {
  756.           stop_print_frame = 0;
  757.           if (stop_breakpoint > 0)
  758.             stop_breakpoint -= 0x1000000;
  759.           else
  760.             stop_breakpoint += 0x1000000;
  761.         }
  762.           break;
  763.         }
  764.       /* But if we have hit the step-resumption breakpoint,
  765.          remove it.  It has done its job getting us here.
  766.          The sp test is to make sure that we don't get hung
  767.          up in recursive calls in functions without frame
  768.          pointers.  If the stack pointer isn't outside of
  769.          where the breakpoint was set (within a routine to be
  770.          stepped over), we're in the middle of a recursive
  771.          call. Not true for reg window machines (sparc)
  772.          because the must change frames to call things and
  773.          the stack pointer doesn't have to change if it
  774.          the bp was set in a routine without a frame (pc can
  775.          be stored in some other window).
  776.          
  777.          The removal of the sp test is to allow calls to
  778.          alloca.  Nasty things were happening.  Oh, well,
  779.          gdb can only handle one level deep of lack of
  780.          frame pointer. */
  781.       if (stop_step_resume_break
  782.           && (step_frame_address == 0
  783.           || (stop_frame_address == step_frame_address)))
  784.         {
  785.           remove_step_breakpoint ();
  786.           step_resume_break_address = 0;
  787.         }
  788.       /* Otherwise, must remove breakpoints and single-step
  789.          to get us past the one we hit.  */
  790.       else
  791.         {
  792.           remove_breakpoints ();
  793.           remove_step_breakpoint ();
  794.           breakpoints_inserted = 0;
  795.           another_trap = 1;
  796.         }
  797.       
  798.       /* We come here if we hit a breakpoint but should not
  799.          stop for it.  Possibly we also were stepping
  800.          and should stop for that.  So fall through and
  801.          test for stepping.  But, if not stepping,
  802.          do not stop.  */
  803.     }
  804.       
  805.       /* If this is the breakpoint at the end of a stack dummy,
  806.      just stop silently.  */
  807. #ifndef CANNOT_EXECUTE_STACK
  808.       if (stop_sp INNER_THAN stop_pc
  809.       && stop_pc INNER_THAN stop_frame_address)
  810. #else
  811.     if (stop_pc == text_end - 2)
  812. #endif
  813.       {
  814.         stop_print_frame = 0;
  815.         stop_stack_dummy = 1;
  816. #ifdef HP_OS_BUG
  817.         trap_expected_after_continue = 1;
  818. #endif
  819.         break;
  820.       }
  821.       
  822.       if (step_resume_break_address)
  823.     /* Having a step-resume breakpoint overrides anything
  824.        else having to do with stepping commands until
  825.        that breakpoint is reached.  */
  826.     ;
  827.       /* If stepping through a line, keep going if still within it.  */
  828.       else if (!random_signal
  829.            && step_range_end
  830.            && stop_pc >= step_range_start
  831.            && stop_pc < step_range_end
  832.            /* The step range might include the start of the
  833.           function, so if we are at the start of the
  834.           step range and either the stack or frame pointers
  835.           just changed, we've stepped outside */
  836.            && !(stop_pc == step_range_start
  837.             && stop_frame_address
  838.             && (stop_sp INNER_THAN prev_sp
  839.             || stop_frame_address != step_frame_address)))
  840.     {
  841.       /* Don't step through the return from a function
  842.          unless that is the first instruction stepped through.  */
  843.       if (ABOUT_TO_RETURN (stop_pc))
  844.         {
  845.           stop_step = 1;
  846.           break;
  847.         }
  848.     }
  849.       
  850.       /* We stepped out of the stepping range.  See if that was due
  851.      to a subroutine call that we should proceed to the end of.  */
  852.       else if (!random_signal && step_range_end)
  853.     {
  854.       if (stop_func_start)
  855.         {
  856.           prologue_pc = stop_func_start;
  857.           SKIP_PROLOGUE (prologue_pc);
  858.         }
  859.  
  860.       /* Did we just take a signal?  */
  861.       if (IN_SIGTRAMP (stop_pc, stop_func_name)
  862.           && !IN_SIGTRAMP (prev_pc, prev_func_name))
  863.         {
  864.           /* This code is needed at least in the following case:
  865.          The user types "next" and then a signal arrives (before
  866.          the "next" is done).  */
  867.           /* We've just taken a signal; go until we are back to
  868.          the point where we took it and one more.  */
  869.           step_resume_break_address = prev_pc;
  870.           step_resume_break_duplicate =
  871.         breakpoint_here_p (step_resume_break_address);
  872.           step_resume_break_sp = stop_sp;
  873.           if (breakpoints_inserted)
  874.         insert_step_breakpoint ();
  875.           /* Make sure that the stepping range gets us past
  876.          that instruction.  */
  877.           if (step_range_end == 1)
  878.         step_range_end = (step_range_start = prev_pc) + 1;
  879.           remove_breakpoints_on_following_step = 1;
  880.         }
  881.  
  882.       /* ==> See comments at top of file on this algorithm.  <==*/
  883.       
  884.       else if (stop_pc == stop_func_start
  885.           && (stop_func_start != prev_func_start
  886.           || prologue_pc != stop_func_start
  887.           || stop_sp != prev_sp))
  888.         {
  889.           /* It's a subroutine call */
  890.           if (step_over_calls > 0 
  891.           || (step_over_calls &&  find_pc_function (stop_pc) == 0))
  892.         {
  893.           /* A subroutine call has happened.  */
  894.           /* Set a special breakpoint after the return */
  895.           step_resume_break_address =
  896.             SAVED_PC_AFTER_CALL (get_current_frame ());
  897.           step_resume_break_duplicate
  898.             = breakpoint_here_p (step_resume_break_address);
  899.           step_resume_break_sp = stop_sp;
  900.           if (breakpoints_inserted)
  901.             insert_step_breakpoint ();
  902.         }
  903.           /* Subroutine call with source code we should not step over.
  904.          Do step to the first line of code in it.  */
  905.           else if (step_over_calls)
  906.         {
  907.           SKIP_PROLOGUE (stop_func_start);
  908.           sal = find_pc_line (stop_func_start, 0);
  909.           /* Use the step_resume_break to step until
  910.              the end of the prologue, even if that involves jumps
  911.              (as it seems to on the vax under 4.2).  */
  912.           /* If the prologue ends in the middle of a source line,
  913.              continue to the end of that source line.
  914.              Otherwise, just go to end of prologue.  */
  915. #ifdef PROLOGUE_FIRSTLINE_OVERLAP
  916.           /* no, don't either.  It skips any code that's
  917.              legitimately on the first line.  */
  918. #else
  919.           if (sal.end && sal.pc != stop_func_start)
  920.             stop_func_start = sal.end;
  921. #endif
  922.           
  923.           if (stop_func_start == stop_pc)
  924.             {
  925.               /* We are already there: stop now.  */
  926.               stop_step = 1;
  927.               break;
  928.             }
  929.           else
  930.             /* Put the step-breakpoint there and go until there. */
  931.             {
  932.               step_resume_break_address = stop_func_start;
  933.               step_resume_break_sp = stop_sp;
  934.               
  935.               step_resume_break_duplicate
  936.             = breakpoint_here_p (step_resume_break_address);
  937.               if (breakpoints_inserted)
  938.             insert_step_breakpoint ();
  939.               /* Do not specify what the fp should be when we stop
  940.              since on some machines the prologue
  941.              is where the new fp value is established.  */
  942.               step_frame_address = 0;
  943.               /* And make sure stepping stops right away then.  */
  944.               step_range_end = step_range_start;
  945.             }
  946.         }
  947.           else
  948.         {
  949.           /* We get here only if step_over_calls is 0 and we
  950.              just stepped into a subroutine.  I presume
  951.              that step_over_calls is only 0 when we're
  952.              supposed to be stepping at the assembly
  953.              language level.*/
  954.           stop_step = 1;
  955.           break;
  956.         }
  957.         }
  958.       /* No subroutince call; stop now.  */
  959.       else
  960.         {
  961.           stop_step = 1;
  962.           break;
  963.         }
  964.     }
  965.  
  966.       /* Save the pc before execution, to compare with pc after stop.  */
  967.       prev_pc = read_pc ();    /* Might have been DECR_AFTER_BREAK */
  968.       prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
  969.                       BREAK is defined, the
  970.                       original pc would not have
  971.                       been at the start of a
  972.                       function. */
  973.       prev_func_name = stop_func_name;
  974.       prev_sp = stop_sp;
  975.  
  976.       /* If we did not do break;, it means we should keep
  977.      running the inferior and not return to debugger.  */
  978.  
  979.       /* If trap_expected is 2, it means continue once more
  980.      and insert breakpoints at the next trap.
  981.      If trap_expected is 1 and the signal was SIGSEGV, it means
  982.      the shell is doing some memory allocation--just resume it
  983.      with SIGSEGV.
  984.      Otherwise insert breakpoints now, and possibly single step.  */
  985.  
  986.       if (trap_expected > 1)
  987.     {
  988.       trap_expected--;
  989.       running_in_shell = 1;
  990.       resume (0, 0);
  991.     }
  992.       else if (running_in_shell && stop_signal == SIGSEGV)
  993.     {
  994.       resume (0, SIGSEGV);
  995.     }
  996.       else if (trap_expected && stop_signal != SIGTRAP)
  997.     {
  998.       /* We took a signal which we are supposed to pass through to
  999.          the inferior and we haven't yet gotten our trap.  Simply
  1000.          continue.  */
  1001.       resume ((step_range_end && !step_resume_break_address)
  1002.           || trap_expected,
  1003.           stop_signal);
  1004.     }
  1005.       else
  1006.     {
  1007.       /* Here, we are not awaiting another exec to get
  1008.          the program we really want to debug.
  1009.          Insert breakpoints now, unless we are trying
  1010.          to one-proceed past a breakpoint.  */
  1011.       running_in_shell = 0;
  1012.       /* If we've just finished a special step resume and we don't
  1013.          want to hit a breakpoint, pull em out.  */
  1014.       if (!step_resume_break_address &&
  1015.           remove_breakpoints_on_following_step)
  1016.         {
  1017.           remove_breakpoints_on_following_step = 0;
  1018.           remove_breakpoints ();
  1019.           breakpoints_inserted = 0;
  1020.         }
  1021.       else if (!breakpoints_inserted && !another_trap)
  1022.         {
  1023.           insert_step_breakpoint ();
  1024.           breakpoints_failed = insert_breakpoints ();
  1025.           if (breakpoints_failed)
  1026.         break;
  1027.           breakpoints_inserted = 1;
  1028.         }
  1029.  
  1030.       trap_expected = another_trap;
  1031.  
  1032.       if (stop_signal == SIGTRAP)
  1033.         stop_signal = 0;
  1034.  
  1035.       resume ((step_range_end && !step_resume_break_address)
  1036.           || trap_expected,
  1037.           stop_signal);
  1038.     }
  1039.     }
  1040. }
  1041.  
  1042. /* Here to return control to GDB when the inferior stops for real.
  1043.    Print appropriate messages, remove breakpoints, give terminal our modes.
  1044.  
  1045.    RUNNING_IN_SHELL nonzero means the shell got a signal before
  1046.    exec'ing the program we wanted to run.
  1047.    STOP_PRINT_FRAME nonzero means print the executing frame
  1048.    (pc, function, args, file, line number and line text).
  1049.    BREAKPOINTS_FAILED nonzero means stop was due to error
  1050.    attempting to insert breakpoints.  */
  1051.  
  1052. static void
  1053. normal_stop ()
  1054. {
  1055.   /* Make sure that the current_frame's pc is correct.  This
  1056.      is a correction for setting up the frame info before doing
  1057.      DECR_PC_AFTER_BREAK */
  1058.   if (inferior_pid)
  1059.     (get_current_frame ())->pc = read_pc ();
  1060.   
  1061.   if (breakpoints_failed)
  1062.     {
  1063.       terminal_ours_for_output ();
  1064.       print_sys_errmsg ("ptrace", breakpoints_failed);
  1065.       printf ("Stopped; cannot insert breakpoints.\n\
  1066. The same program may be running in another process.\n");
  1067.     }
  1068.  
  1069.   if (inferior_pid)
  1070.     remove_step_breakpoint ();
  1071.  
  1072.   if (inferior_pid && breakpoints_inserted)
  1073.     if (remove_breakpoints ())
  1074.       {
  1075.     terminal_ours_for_output ();
  1076.     printf ("Cannot remove breakpoints because program is no longer writable.\n\
  1077. It must be running in another process.\n\
  1078. Further execution is probably impossible.\n");
  1079.       }
  1080.  
  1081.   breakpoints_inserted = 0;
  1082.  
  1083.   /* Delete the breakpoint we stopped at, if it wants to be deleted.
  1084.      Delete any breakpoint that is to be deleted at the next stop.  */
  1085.  
  1086.   breakpoint_auto_delete (stop_breakpoint);
  1087.  
  1088.   /* If an auto-display called a function and that got a signal,
  1089.      delete that auto-display to avoid an infinite recursion.  */
  1090.  
  1091.   if (stopped_by_random_signal)
  1092.     disable_current_display ();
  1093.  
  1094.   if (step_multi && stop_step)
  1095.     return;
  1096.  
  1097.   terminal_ours ();
  1098.  
  1099.   if (running_in_shell)
  1100.     {
  1101.       if (stop_signal == SIGSEGV)
  1102.     {
  1103.       char *exec_file = (char *) get_exec_file (1);
  1104.  
  1105.       if (access (exec_file, X_OK) != 0)
  1106.         printf ("The file \"%s\" is not executable.\n", exec_file);
  1107.       else
  1108.         /* I don't think we should ever get here.
  1109.            wait_for_inferior now ignores SIGSEGV's which happen in
  1110.            the shell (since the Bourne shell (/bin/sh) has some
  1111.            rather, er, uh, *unorthodox* memory management
  1112.            involving catching SIGSEGV).  */
  1113.         printf ("\
  1114. You have just encountered a bug in \"sh\".  GDB starts your program\n\
  1115. by running \"sh\" with a command to exec your program.\n\
  1116. This is so that \"sh\" will process wildcards and I/O redirection.\n\
  1117. This time, \"sh\" crashed.\n\
  1118. \n\
  1119. One known bug in \"sh\" bites when the environment takes up a lot of space.\n\
  1120. Try \"info env\" to see the environment; then use \"delete env\" to kill\n\
  1121. some variables whose values are large; then do \"run\" again.\n\
  1122. \n\
  1123. If that works, you might want to put those \"delete env\" commands\n\
  1124. into a \".gdbinit\" file in this directory so they will happen every time.\n");
  1125.     }
  1126.       /* Don't confuse user with his program's symbols on sh's data.  */
  1127.       stop_print_frame = 0;
  1128.     }
  1129.  
  1130.   if (inferior_pid == 0)
  1131.     return;
  1132.  
  1133.   /* Select innermost stack frame except on return from a stack dummy routine,
  1134.      or if the program has exited.  */
  1135.   if (!stop_stack_dummy)
  1136.     {
  1137.       select_frame (get_current_frame (), 0);
  1138.  
  1139.       if (stop_print_frame)
  1140.     {
  1141.       if (stop_breakpoint > 0)
  1142.         printf ("\nBpt %d, ", stop_breakpoint);
  1143.       print_sel_frame (stop_step
  1144.                && step_frame_address == stop_frame_address
  1145.                && step_start_function == find_pc_function (stop_pc));
  1146.       /* Display the auto-display expressions.  */
  1147.       do_displays ();
  1148.     }
  1149.     }
  1150.  
  1151.   /* Save the function value return registers
  1152.      We might be about to restore their previous contents.  */
  1153.   read_register_bytes (0, stop_registers, REGISTER_BYTES);
  1154.  
  1155.   if (stop_stack_dummy)
  1156.     {
  1157.       /* Pop the empty frame that contains the stack dummy.
  1158.          POP_FRAME ends with a setting of the current frame, so we
  1159.      can use that next. */
  1160.       POP_FRAME;
  1161.       select_frame (get_current_frame (), 0);
  1162.     }
  1163. }
  1164.  
  1165. static void
  1166. insert_step_breakpoint ()
  1167. {
  1168.   if (step_resume_break_address && !step_resume_break_duplicate)
  1169.     {
  1170.       read_memory (step_resume_break_address,
  1171.            step_resume_break_shadow, sizeof break_insn);
  1172.       write_memory (step_resume_break_address,
  1173.             break_insn, sizeof break_insn);
  1174.     }
  1175. }
  1176.  
  1177. static void
  1178. remove_step_breakpoint ()
  1179. {
  1180.   if (step_resume_break_address && !step_resume_break_duplicate)
  1181.     write_memory (step_resume_break_address, step_resume_break_shadow,
  1182.           sizeof break_insn);
  1183. }
  1184.  
  1185. /* Specify how various signals in the inferior should be handled.  */
  1186.  
  1187. static void
  1188. handle_command (args, from_tty)
  1189.      char *args;
  1190.      int from_tty;
  1191. {
  1192.   register char *p = args;
  1193.   int signum = 0;
  1194.   register int digits, wordlen;
  1195.  
  1196.   if (!args)
  1197.     error_no_arg ("signal to handle");
  1198.  
  1199.   while (*p)
  1200.     {
  1201.       /* Find the end of the next word in the args.  */
  1202.       for (wordlen = 0; p[wordlen] && p[wordlen] != ' ' && p[wordlen] != '\t';
  1203.        wordlen++);
  1204.       for (digits = 0; p[digits] >= '0' && p[digits] <= '9'; digits++);
  1205.  
  1206.       /* If it is all digits, it is signal number to operate on.  */
  1207.       if (digits == wordlen)
  1208.     {
  1209.       signum = atoi (p);
  1210.       if (signum <= 0 || signum >= NSIG)
  1211.         {
  1212.           p[wordlen] = '\0';
  1213.           error ("Invalid signal %s given as argument to \"handle\".", p);
  1214.         }
  1215.       if (signum == SIGTRAP || signum == SIGINT)
  1216.         {
  1217.           if (!query ("Signal %d is used by the debugger.\nAre you sure you want to change it? ", signum))
  1218.         error ("Not confirmed.");
  1219.         }
  1220.     }
  1221.       else if (signum == 0)
  1222.     error ("First argument is not a signal number.");
  1223.  
  1224.       /* Else, if already got a signal number, look for flag words
  1225.      saying what to do for it.  */
  1226.       else if (!strncmp (p, "stop", wordlen))
  1227.     {
  1228.       signal_stop[signum] = 1;
  1229.       signal_print[signum] = 1;
  1230.     }
  1231.       else if (wordlen >= 2 && !strncmp (p, "print", wordlen))
  1232.     signal_print[signum] = 1;
  1233.       else if (wordlen >= 2 && !strncmp (p, "pass", wordlen))
  1234.     signal_program[signum] = 1;
  1235.       else if (!strncmp (p, "ignore", wordlen))
  1236.     signal_program[signum] = 0;
  1237.       else if (wordlen >= 3 && !strncmp (p, "nostop", wordlen))
  1238.     signal_stop[signum] = 0;
  1239.       else if (wordlen >= 4 && !strncmp (p, "noprint", wordlen))
  1240.     {
  1241.       signal_print[signum] = 0;
  1242.       signal_stop[signum] = 0;
  1243.     }
  1244.       else if (wordlen >= 4 && !strncmp (p, "nopass", wordlen))
  1245.     signal_program[signum] = 0;
  1246.       else if (wordlen >= 3 && !strncmp (p, "noignore", wordlen))
  1247.     signal_program[signum] = 1;
  1248.       /* Not a number and not a recognized flag word => complain.  */
  1249.       else
  1250.     {
  1251.       p[wordlen] = 0;
  1252.       error ("Unrecognized flag word: \"%s\".", p);
  1253.     }
  1254.  
  1255.       /* Find start of next word.  */
  1256.       p += wordlen;
  1257.       while (*p == ' ' || *p == '\t') p++;
  1258.     }
  1259.  
  1260.   if (from_tty)
  1261.     {
  1262.       /* Show the results.  */
  1263.       printf ("Number\tStop\tPrint\tPass to program\tDescription\n");
  1264.       printf ("%d\t", signum);
  1265.       printf ("%s\t", signal_stop[signum] ? "Yes" : "No");
  1266.       printf ("%s\t", signal_print[signum] ? "Yes" : "No");
  1267.       printf ("%s\t\t", signal_program[signum] ? "Yes" : "No");
  1268.       printf ("%s\n", sys_siglist[signum]);
  1269.     }
  1270. }
  1271.  
  1272. /* Print current contents of the tables set by the handle command.  */
  1273.  
  1274. static void
  1275. signals_info (signum_exp)
  1276.      char *signum_exp;
  1277. {
  1278.   register int i;
  1279.   printf_filtered ("Number\tStop\tPrint\tPass to program\tDescription\n");
  1280.  
  1281.   if (signum_exp)
  1282.     {
  1283.       i = parse_and_eval_address (signum_exp);
  1284.       if (i >= NSIG || i < 0)
  1285.     error ("Signal number out of bounds.");
  1286.       printf_filtered ("%d\t", i);
  1287.       printf_filtered ("%s\t", signal_stop[i] ? "Yes" : "No");
  1288.       printf_filtered ("%s\t", signal_print[i] ? "Yes" : "No");
  1289.       printf_filtered ("%s\t\t", signal_program[i] ? "Yes" : "No");
  1290.       printf_filtered ("%s\n", sys_siglist[i]);
  1291.       return;
  1292.     }
  1293.  
  1294.   printf_filtered ("\n");
  1295.   for (i = 0; i < NSIG; i++)
  1296.     {
  1297.       QUIT;
  1298.  
  1299.       printf_filtered ("%d\t", i);
  1300.       printf_filtered ("%s\t", signal_stop[i] ? "Yes" : "No");
  1301.       printf_filtered ("%s\t", signal_print[i] ? "Yes" : "No");
  1302.       printf_filtered ("%s\t\t", signal_program[i] ? "Yes" : "No");
  1303.       printf_filtered ("%s\n", sys_siglist[i]);
  1304.     }
  1305.  
  1306.   printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
  1307. }
  1308.  
  1309. /* Save all of the information associated with the inferior<==>gdb
  1310.    connection.  INF_STATUS is a pointer to a "struct inferior_status"
  1311.    (defined in inferior.h).  */
  1312.  
  1313. struct command_line *get_breakpoint_commands ();
  1314.  
  1315. void
  1316. save_inferior_status (inf_status, restore_stack_info)
  1317.      struct inferior_status *inf_status;
  1318.      int restore_stack_info;
  1319. {
  1320.   inf_status->pc_changed = pc_changed;
  1321.   inf_status->stop_signal = stop_signal;
  1322.   inf_status->stop_pc = stop_pc;
  1323.   inf_status->stop_frame_address = stop_frame_address;
  1324.   inf_status->stop_breakpoint = stop_breakpoint;
  1325.   inf_status->stop_step = stop_step;
  1326.   inf_status->stop_stack_dummy = stop_stack_dummy;
  1327.   inf_status->stopped_by_random_signal = stopped_by_random_signal;
  1328.   inf_status->trap_expected = trap_expected;
  1329.   inf_status->step_range_start = step_range_start;
  1330.   inf_status->step_range_end = step_range_end;
  1331.   inf_status->step_frame_address = step_frame_address;
  1332.   inf_status->step_over_calls = step_over_calls;
  1333.   inf_status->step_resume_break_address = step_resume_break_address;
  1334.   inf_status->stop_after_trap = stop_after_trap;
  1335.   inf_status->stop_after_attach = stop_after_attach;
  1336.   inf_status->breakpoint_commands = get_breakpoint_commands ();
  1337.   inf_status->restore_stack_info = restore_stack_info;
  1338.   
  1339.   bcopy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
  1340.   
  1341.   record_selected_frame (&(inf_status->selected_frame_address),
  1342.              &(inf_status->selected_level));
  1343.   return;
  1344. }
  1345.  
  1346. void
  1347. restore_inferior_status (inf_status)
  1348.      struct inferior_status *inf_status;
  1349. {
  1350.   FRAME fid;
  1351.   int level = inf_status->selected_level;
  1352.  
  1353.   pc_changed = inf_status->pc_changed;
  1354.   stop_signal = inf_status->stop_signal;
  1355.   stop_pc = inf_status->stop_pc;
  1356.   stop_frame_address = inf_status->stop_frame_address;
  1357.   stop_breakpoint = inf_status->stop_breakpoint;
  1358.   stop_step = inf_status->stop_step;
  1359.   stop_stack_dummy = inf_status->stop_stack_dummy;
  1360.   stopped_by_random_signal = inf_status->stopped_by_random_signal;
  1361.   trap_expected = inf_status->trap_expected;
  1362.   step_range_start = inf_status->step_range_start;
  1363.   step_range_end = inf_status->step_range_end;
  1364.   step_frame_address = inf_status->step_frame_address;
  1365.   step_over_calls = inf_status->step_over_calls;
  1366.   step_resume_break_address = inf_status->step_resume_break_address;
  1367.   stop_after_trap = inf_status->stop_after_trap;
  1368.   stop_after_attach = inf_status->stop_after_attach;
  1369.   set_breakpoint_commands (inf_status->breakpoint_commands);
  1370.  
  1371.   bcopy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
  1372.  
  1373.   /* The inferior can be gone if the user types "print exit(0)"
  1374.      (and perhaps other times).  */
  1375.   if (have_inferior_p() && inf_status->restore_stack_info)
  1376.     {
  1377.       fid = find_relative_frame (get_current_frame (),
  1378.                  &level);
  1379.  
  1380.       if (fid == 0 ||
  1381.       FRAME_FP (fid) != inf_status->selected_frame_address ||
  1382.       level != 0)
  1383.     {
  1384.       /* I'm not sure this error message is a good idea.  I have
  1385.          only seen it occur after "Can't continue previously
  1386.          requested operation" (we get called from do_cleanups), in
  1387.          which case it just adds insult to injury (one confusing
  1388.          error message after another.  Besides which, does the
  1389.          user really care if we can't restore the previously
  1390.          selected frame?  */
  1391.       fprintf (stderr, "Unable to restore previously selected frame.\n");
  1392.       select_frame (get_current_frame (), 0);
  1393.       return;
  1394.     }
  1395.       
  1396.       select_frame (fid, inf_status->selected_level);
  1397.     }
  1398.   return;
  1399. }
  1400.  
  1401.  
  1402. void
  1403. _initialize_infrun ()
  1404. {
  1405.   register int i;
  1406.  
  1407.   add_info ("signals", signals_info,
  1408.         "What debugger does when program gets various signals.\n\
  1409. Specify a signal number as argument to print info on that signal only.");
  1410.  
  1411.   add_com ("handle", class_run, handle_command,
  1412.        "Specify how to handle a signal.\n\
  1413. Args are signal number followed by flags.\n\
  1414. Flags allowed are \"stop\", \"print\", \"pass\",\n\
  1415.  \"nostop\", \"noprint\" or \"nopass\".\n\
  1416. Print means print a message if this signal happens.\n\
  1417. Stop means reenter debugger if this signal happens (implies print).\n\
  1418. Pass means let program see this signal; otherwise program doesn't know.\n\
  1419. Pass and Stop may be combined.");
  1420.  
  1421.   for (i = 0; i < NSIG; i++)
  1422.     {
  1423.       signal_stop[i] = 1;
  1424.       signal_print[i] = 1;
  1425.       signal_program[i] = 1;
  1426.     }
  1427.  
  1428.   /* Signals caused by debugger's own actions
  1429.      should not be given to the program afterwards.  */
  1430.   signal_program[SIGTRAP] = 0;
  1431.   signal_program[SIGINT] = 0;
  1432.  
  1433.   /* Signals that are not errors should not normally enter the debugger.  */
  1434. #ifdef SIGALRM
  1435.   signal_stop[SIGALRM] = 0;
  1436.   signal_print[SIGALRM] = 0;
  1437. #endif /* SIGALRM */
  1438. #ifdef SIGVTALRM
  1439.   signal_stop[SIGVTALRM] = 0;
  1440.   signal_print[SIGVTALRM] = 0;
  1441. #endif /* SIGVTALRM */
  1442. #ifdef SIGPROF
  1443.   signal_stop[SIGPROF] = 0;
  1444.   signal_print[SIGPROF] = 0;
  1445. #endif /* SIGPROF */
  1446. #ifdef SIGCHLD
  1447.   signal_stop[SIGCHLD] = 0;
  1448.   signal_print[SIGCHLD] = 0;
  1449. #endif /* SIGCHLD */
  1450. #ifdef SIGCLD
  1451.   signal_stop[SIGCLD] = 0;
  1452.   signal_print[SIGCLD] = 0;
  1453. #endif /* SIGCLD */
  1454. #ifdef SIGIO
  1455.   signal_stop[SIGIO] = 0;
  1456.   signal_print[SIGIO] = 0;
  1457. #endif /* SIGIO */
  1458. #ifdef SIGURG
  1459.   signal_stop[SIGURG] = 0;
  1460.   signal_print[SIGURG] = 0;
  1461. #endif /* SIGURG */
  1462. }
  1463.  
  1464.